package com.wh.controller;

import com.legend.utils.RandomValidateCode;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.MessageFormat;

/**
 * Created by ayakatsune on 14-8-30.
 */
@Controller
public class MainController {
    @RequestMapping({"{page1}","{page1}/{page2}"})
    public ModelAndView main()
    {
        ModelAndView mv=new ModelAndView();
        mv.addObject("test","hello let's me see see");
        mv.setViewName("work/main");
        return mv;
    }
    @RequestMapping("login")
    public ModelAndView main3()
    {
        ModelAndView mv=new ModelAndView();
        mv.addObject("test","hello let's me see see login");
        mv.setViewName("work/login");
        return mv;
    }
    /**
     *验证码
     * @param request
     * @param response
     */
    @ResponseBody
    @RequestMapping(value = "validcode", method = RequestMethod.GET)
    public void validateCode(HttpServletRequest request, HttpServletResponse response) {
        response.setContentType("image/jpeg");
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expire", 0);
        RandomValidateCode randomValidateCode = new RandomValidateCode();
        try {
            randomValidateCode.getRandcode(request, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
